<template>
	<view>
		<view class="image">
			<image style="width: 100%;" mode="widthFix" src="https://img1.baidu.com/it/u=3796733882,1498058766&fm=253&fmt=auto&app=138&f=JPEG?w=999&h=500"></image>
		</view>
		<view class="title">{{ info.formName }}</view>
		<view class="form">
			<uv-form labelPosition="left" :model="userInfo" ref="uvFormRef" label-width="70">
				<uv-form-item v-if="info.formName!='注册公司'" label="公司名称" prop="userInfo.corporateName" borderBottom ref="item1">
					<uv-input v-model="userInfo.corporateName" border="none" placeholder="请输入内容"></uv-input>
				</uv-form-item>
				<uv-form-item label="联系人" prop="userInfo.contactsName" borderBottom ref="item1">
					<uv-input v-model="userInfo.contactsName" border="none" placeholder="请输入内容"></uv-input>
				</uv-form-item>
				<uv-form-item label="电话" prop="userInfo.mobile" borderBottom ref="item1">
					<uv-input v-model="userInfo.mobile" border="none" placeholder="请输入内容"></uv-input>
				</uv-form-item>
				<uv-form-item label="图片上传" prop="userInfo.mobile" borderBottom ref="item1">
					<view
						class=""
						v-if="!userInfo.images"
						style="width: 100rpx;height: 100rpx;background-color: #f5f5f5;display: flex;justify-content: center;align-content: center;border: 1rpx solid #f5f5f5;"
						@click="updateHeadimg"
					>
						<uv-icon name="photo" size="50"></uv-icon>
					</view>
					<view class="" v-else style="width: 200rpx;height: 100rpx;">
						<image style="width: 200rpx;height: 100rpx;" :src="userInfo.images"></image>
					</view>
				</uv-form-item>
				<view class="name" v-if="info.formName=='营运证'">输入车牌号码</view>
				<view  class="" v-if="info.formName=='营运证'" style="display: flex;align-items: center;flex-wrap: wrap;">
					<view class="" style="display: flex;width: 200rpx;margin-bottom: 10rpx;margin-right: 10px;" v-for="item in carNumberList">
						(沪 <uv-input v-model="item.car" border="none" custom-style="border-bottom:1rpx solid #333;border-radius:0" placeholder="请输入内容"></uv-input>)
					</view>
				</view>
				
				<view class="name">备注说明</view>
				<uv-textarea v-model="userInfo.remarks" placeholder="请输入内容"></uv-textarea>
				<view class="" v-if="info.formName=='营运证'" style="margin-top: 20rpx;">
					<checkbox @click="changeBox('yyzxz')" :checked="userInfo.yyzxz">营运证新增</checkbox>
					<checkbox @click="changeBox('yyzbz')" :checked="userInfo.yyzbz">营运证补证</checkbox>
					<checkbox @click="changeBox('yyzzx')" :checked="userInfo.yyzzx">营运证注销</checkbox>
					<view class="" style="margin-top: 10rpx;">
						<checkbox @click="changeBox('yyzhz')" :checked="userInfo.yyzhz">营运证换证</checkbox>
						<checkbox @click="changeBox('yyzns')" :checked="userInfo.yyzns">营运证年审</checkbox>
					</view>
					
				</view>
				<uv-button type="primary" text="提交" customStyle="margin-top: 30px;border-radio:20rpx" @click="submit"></uv-button>
			</uv-form>
		</view>
	</view>
</template>

<script>
	import {insertPlugsFormData,uploadImages} from '../../utils/api.js'
export default {
	data() {
		return {
			userInfo: {
				corporateName: '',
				mobile: '',
				contactsName: '',
				yyzxz: false,
				yyzhz: false,
				yyzns: false,
				yyzzx: false,
				yyzbz: false,
				remarks: '',
				carNumber:'',
				images:''
			},
			info: {},
			carNumberList:[
				{
					car:''
				},
				{
					car:''
				},
				{
					car:''
				},
				{
					car:''
				},
				{
					car:''
				},
			]
		};
	},
	onLoad(option) {
		this.info = JSON.parse(decodeURIComponent(option.info));
	},
	methods: {
		// yyzxz: true,
		// yyzhz: '',
		// yyzns: '',
		// yyzzx: '',
		// yyzbz: '',
		changeBox(name){
			this.userInfo[name]=!this.userInfo[name]
		},
		updateHeadimg(){
			let that=this
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], //从相册选择
				loop: true,
				success: res => {
					console.log(res);
						let data={
							file:res.tempFilePaths[0], //你要传的临时文件
							type:1
						}
					uploadImages(data).then(ress=>{
						if(ress.code==200){
							that.info.images=ress.body 
							console.log(that.info.headImg)
						}
					})
		
				}
			});
					
		
		},
		submit() {
			let list=[]
			this.carNumberList.forEach((item)=>{
				list.push(item.car)
			})
			this.userInfo.carNumber=list.join()
			console.log(this.userInfo);
			if (!this.userInfo.contactsName) {
				uni.showToast({
					icon: 'none',
					title: '请输入姓名'
				});
				return;
			} else if (!this.userInfo.mobile) {
				uni.showToast({
					icon: 'none',
					title: '请输入手机号'
				});
				return;
			}
			let data={
					  "dataJson": JSON.stringify(this.userInfo),
					  "formId": this.info.id,
					  "userId":uni.getStorageSync('userInfo').id
					}
					console.log(data);
			insertPlugsFormData(data).then(res=>{
				if(res.code==200){
					setTimeout(()=>{
						uni.showModal({
							title: '提示',
							content: '信息提交成功，点击确定返回上一页',
							showCancel: false,
							success: () => {
								uni.navigateBack();
							}
						});
					},500)
				}
			})
			
		}
	}
};
</script>

<style lang="scss">
page {
	padding: 20rpx;
	background-color: $uni-bg-color;
	box-sizing: border-box;
}
.image {
	image {
		border-radius: 20rpx;
	}
}
.title {
	font-size: 32rpx;
	color: $uni-text-color;
	font-weight: 700;
	text-align: center;
	margin: 20rpx;
}
.form {
	padding: 20rpx;
	.name {
		font-size: 28rpx;
		color: $uni-text-color;
		margin: 20rpx 0;
	}
}
</style>
